Plot duplications in tree

Author

Claudia Zirión-Martínez

Published

February 13, 2025

Setup

Libraries

Code
library(tidyverse)
library(ggtree)
library(ggtreeExtra)
library(ape)
library(ggnewscale)
library(RColorBrewer)
library(svglite)
source("scripts/metadata_colors.R")

Paths

Code
metadata_path <- 
    "data/processed/metadata_ashton_desj_all_weavepop_final_H99.csv"
duplications_path <- 
    "results/tables/duplications.tsv"
merged_tree_path <- 
    "data/processed/tree_merged.newick"
tree_merged_duplications_path1 <- 
    "results/trees_dups/tree_duplications_full1.png"
tree_merged_duplications_path2 <- 
    "results/trees_dups/tree_duplications_full2.png"
tree_merged_duplications_path3 <- 
    "results/trees_dups/tree_duplications_full3.png"
tree_merged_duplications_path4 <- 
    "results/trees_dups/tree_duplications_full4.png"
tree_merged_duplications_path5 <- 
    "results/trees_dups/tree_duplications_full5.png"
tree_merged_duplications_path6 <- 
    "results/trees_dups/tree_duplications_full6.png"
tree_merged_duplications_small1 <-  
    "results/trees_dups/tree_duplications_small1.png"
tree_merged_duplications_small2 <-  
    "results/trees_dups/tree_duplications_small2.png"
tree_merged_duplications_small3 <-  
    "results/trees_dups/tree_duplications_small3.png"
tree_merged_duplications_small4 <-  
    "results/trees_dups/tree_duplications_small4.png"
tree_merged_duplications_small5 <-  
    "results/trees_dups/tree_duplications_small5.png"
tree_merged_duplications_small6 <-  
    "results/trees_dups/tree_duplications_small6.png"
tree_merged_duplications_small7 <-  
    "results/trees_dups/tree_duplications_small7.png"
tree_merged_duplications_small8 <-  
    "results/trees_dups/tree_duplications_small8.png"
tree_merged_duplications_small9 <-  
    "results/trees_dups/tree_duplications_small9.png"
tree_merged_duplications_small10 <-  
    "results/trees_dups/tree_duplications_small10.png"

Metadata

Load the necessary data

Code
metadata <- read.csv(
    metadata_path,
    header = TRUE)%>%
    select(strain, everything())

Get one dataframe for each variable to be plotted as a separate metadata column in the tree

Code
metadata$vni_subdivision <- factor(metadata$vni_subdivision,
                            levels = c("VNIa-4", "VNIa-5", "VNIa-32", 
                            "VNIa-93", "VNIa-X", "VNIa-Y", "VNIb", 
                            "VNIc", "VNIa-outlier"))
metadata$country_of_origin <- factor(metadata$country_of_origin,
                                levels = names(country_colors))

sublineage <- metadata %>%
                filter(lineage == "VNI")%>%
                select(strain, vni_subdivision)%>%
                column_to_rownames("strain")%>%
                droplevels()
lineage <- metadata %>%
            select(strain, lineage)%>%
            column_to_rownames("strain")
dataset <- metadata %>%
            select(strain, dataset)%>%
            column_to_rownames("strain")
source <- metadata %>%
            select(strain, source)%>%
            column_to_rownames("strain")
country <- metadata %>%
            select(strain, country_of_origin)%>%
            column_to_rownames("strain")     

Duplications

Code
duplications <- read.delim(
    duplications_path,
    sep = "\t", header = TRUE, stringsAsFactors = TRUE)
Code
duplications_full <- duplications %>%
    select(strain, chromosome) %>%
    distinct()

Make matrix of duplicated chromosomes

Code
dup_chroms <- duplications_full %>%
    select(strain, chromosome)%>%
    mutate(duplicated_full = 1)%>%
    arrange(chromosome)%>%
    pivot_wider(names_from = chromosome, values_from = duplicated_full, values_fill = 0)%>%
    column_to_rownames("strain")%>%
    mutate(across(everything(), ~ ifelse(. == 1, cur_column(),"Euploid")))

euploid_strain <- metadata %>%
    filter(!strain %in% duplications_full$strain)%>%
    select(strain)

for (chrom in colnames(dup_chroms)){
    euploid_strain[chrom] <- "Euploid"
}

dup_chroms <- euploid_strain %>%
    column_to_rownames("strain") %>%
    bind_rows(dup_chroms)

Tree

Code
tree <- read.tree(merged_tree_path)

Remove tips that are not in metadata$strain

Code
tree <- drop.tip(tree, setdiff(tree$tip.label, metadata$strain))

Tree info

Get the node number of the Most Recent Common Ancestor of each lineage

Code
VNI_node <- getMRCA(tree, c("Tu241-1","UI_31647-2"))
VNII_node <- getMRCA(tree, c("C2","C12"))
VNBI_node <- getMRCA(tree, c("Tu229-1","Ftc267-2"))
VNBII_node <- getMRCA(tree, c("MW-RSA3321","MW-RSA3179"))

nodes_lineages <- data.frame(
    lineage = c("VNI", "VNII", "VNBI", "VNBII"),
    mrca = c(VNI_node, VNII_node, VNBI_node, VNBII_node)
)

Nodes of VNI sublineages

Code
VNIa4_node <- getMRCA(tree, c("04CN-30-008","UI_31647-2"))
VNIa5_node <- getMRCA(tree, c("BMD852","14936_1#45"))
VNIa93_node <- getMRCA(tree, c("04CN-65-080","04CN-65-002"))
VNIa32_node <- getMRCA(tree, c("BMD942","BMD2801"))
VNIaX_node <- getMRCA(tree, c("Bt48","04CN-63-007"))
VNIaY_node <- getMRCA(tree, c("04CN-65-073","Bt138"))
VNIb_node <- getMRCA(tree, c("04CN-65-096","MW-RSA722"))
VNIc_node <- getMRCA(tree, c("Bt20","Bt11"))

nodes_vnisublineages <- data.frame(
    sublineage = c(
                "VNIa-4", "VNIa-5", "VNIa-93",
                "VNIa-32", "VNIa-X", "VNIa-Y",
                "VNIb", "VNIc"),
    mrca = c(
            VNIa4_node, VNIa5_node, VNIa93_node,
            VNIa32_node, VNIaX_node, VNIaY_node,
            VNIb_node, VNIc_node))

Nodes of lineages and VNI sublineages

Code
nodes_sublineages <- data.frame(
    sublineage = c("VNII", "VNBI", "VNBII",
                "VNIa-4", "VNIa-5", "VNIa-93",
                "VNIa-32", "VNIa-X", "VNIa-Y",
                "VNIb", "VNIc"),
    mrca = c(VNII_node, VNBI_node, VNBII_node,
            VNIa4_node, VNIa5_node, VNIa93_node,
            VNIa32_node, VNIaX_node, VNIaY_node,
            VNIb_node, VNIc_node))

Plots

Code
chrom_colors <- brewer.pal(7, "Dark2")
names(chrom_colors) <- c("chr01", "chr04",
                         "chr06", "chr09", 
                         "chr12","chr13", "chr14")
chrom_dup_colors <- c(chrom_colors, "Euploid" = "grey93")

countries_final <- levels(droplevels(country[rownames(country) %in% tree$tip.label, ]))

Country, source, duplications in one ring per chromosome

Code
a <- ggtree(tree, 
        ladderize = TRUE,
        layout = "circular", 
        branch.length = "none",
        size = 0.1) %<+%  metadata +
    geom_tiplab(color = "black", size = 0.3, offset = 0.01)+
    geom_hilight(data=nodes_vnisublineages, 
        aes(node=mrca, fill=sublineage), alpha = 0.8)+
        scale_fill_manual(name = "Sublineage", values = vnisublineage_shading)+
    guides(fill = FALSE)+
    new_scale_fill()+
    geom_tree(size = 0.1)+
    geom_text(aes(label = nodes_lineages$lineage[match(node, nodes_lineages$mrca)]), 
                        size = 2, , fontface = "bold",
                        hjust = 1.25, vjust = -0.5)+
    geom_tippoint(aes(color = country_of_origin), shape = 18,
                size = 0.01)+
    scale_color_manual(name = "Country", values = country_colors,
                        limits = countries_final)+
    guides(color = guide_legend(override.aes = list(size = 5), order = 1, ncol = 2))

a1 <- gheatmap(a, source, width=.05, colnames=FALSE, offset=3.7) +
        scale_fill_manual(values = source_colors, name="Source", na.translate = FALSE)+
        guides(fill = guide_legend(order = 2))+
        new_scale_fill()
a2 <- gheatmap(a1, dup_chroms, width=.32, colnames = FALSE, offset=6) +
    scale_fill_manual(values = chrom_dup_colors, 
                    name="Duplicated\nchromosomes", 
                    na.translate = FALSE )+
    guides(fill = guide_legend(order = 5))+
        geom_cladelab(data = nodes_vnisublineages, 
                mapping = aes(node = mrca, label = sublineage),
                align = TRUE, face = "bold",
                fontsize = 3,
                angle = "auto", offset = 20)+
    theme(legend.position = "bottom",
    legend.direction = "vertical")
a2

Code
ggsave(tree_merged_duplications_path1, a2, height = 8, width = 6.5, units = "in", dpi = 1000)
Warning: Removed 2047 rows containing missing values or values outside the scale range
(`geom_text()`).

Country, source, duplications in one ring per chromosome, lineage and sublineage shading

Code
m <- ggtree(tree, 
        ladderize = TRUE,
        layout = "circular", 
        branch.length = "none",
        size = 0.1) %<+%  metadata +
    geom_tiplab(color = "black", size = 0.3, offset = 0.01)+
    geom_hilight(data=nodes_sublineages, 
        aes(node=mrca, fill=sublineage), alpha = 0.8)+
        scale_fill_manual(name = "Sublineage", values = sublineage_shading)+
    guides(fill = FALSE)+
    new_scale_fill()+
    geom_tree(size = 0.1)+
    geom_text(aes(label = nodes_lineages$lineage[match(node, nodes_lineages$mrca)]), 
                        size = 2, , fontface = "bold",
                        hjust = 1.25, vjust = -0.5)+
    geom_tippoint(aes(color = country_of_origin), shape = 18,
                size = 0.01)+
    scale_color_manual(name = "Country", values = country_colors,
                        limits = countries_final)+
    guides(color = guide_legend(override.aes = list(size = 5), order = 1, ncol = 2))

m1 <- gheatmap(m, source, width=.05, colnames=FALSE, offset=3.7) +
        scale_fill_manual(values = source_colors, name="Source", na.translate = FALSE)+
        guides(fill = guide_legend(order = 2))+
        new_scale_fill()
m2 <- gheatmap(m1, dup_chroms, width=.32, colnames = FALSE, offset=6) +
    scale_fill_manual(values = chrom_dup_colors, 
                    name="Duplicated\nchromosomes", 
                    na.translate = FALSE )+
    guides(fill = guide_legend(order = 5))+
        geom_cladelab(data = nodes_vnisublineages, 
                mapping = aes(node = mrca, label = sublineage),
                align = TRUE, face = "bold",
                fontsize = 3,
                angle = "auto", offset = 20)+
    theme(legend.position = "bottom",
    legend.direction = "vertical")
m2

Code
ggsave(tree_merged_duplications_path2, m2, height = 8, width = 6.5, units = "in", dpi = 1000)
Warning: Removed 2047 rows containing missing values or values outside the scale range
(`geom_text()`).

Country, source, duplications in one ring per chromosome, lineage and sublineage labels

Code
m <- ggtree(tree, 
        ladderize = TRUE,
        layout = "circular", 
        branch.length = "none",
        size = 0.1) %<+%  metadata +
    geom_tiplab(color = "black", size = 0.3, offset = 0.01)+
    geom_hilight(data=nodes_sublineages, 
        aes(node=mrca, fill=sublineage), alpha = 0.8)+
        scale_fill_manual(name = "Sublineage", values = sublineage_shading)+
    guides(fill = FALSE)+
    new_scale_fill()+
    geom_tree(size = 0.1)+
    geom_tippoint(aes(color = country_of_origin), shape = 18,
                size = 0.01)+
    scale_color_manual(name = "Country", values = country_colors,
                        limits = countries_final)+
    guides(color = guide_legend(override.aes = list(size = 5), order = 1, ncol = 2))

m1 <- gheatmap(m, source, width=.05, colnames=FALSE, offset=3.7) +
        scale_fill_manual(values = source_colors, name="Source", na.translate = FALSE)+
        guides(fill = guide_legend(order = 2))+
        new_scale_fill()
m2 <- gheatmap(m1, dup_chroms, width=.32, colnames = FALSE, offset=6) +
    scale_fill_manual(values = chrom_dup_colors, 
                    name="Duplicated\nchromosomes", 
                    na.translate = FALSE )+
    guides(fill = guide_legend(order = 5))+
        geom_cladelab(data = nodes_sublineages, 
                mapping = aes(node = mrca, label = sublineage),
                align = TRUE, face = "bold",
                fontsize = 3,
                angle = "auto", offset = 20)+
    theme(legend.position = "bottom",
    legend.direction = "vertical")
m2

Code
ggsave(tree_merged_duplications_path3, m2, height = 8, width = 6.5, units = "in", dpi = 1000)

Country, source and duplications in one ring

Code
aneuploid <- duplications_full %>%
    group_by(strain)%>%
    summarise(chromosome = str_c(chromosome, collapse="_")) %>%
    right_join(select(metadata, strain), by = "strain")%>%
    mutate(chromosome = ifelse(is.na(chromosome), "Euploid", chromosome))%>%
    column_to_rownames("strain")
Code
dup_colors <- brewer.pal(8, "Dark2")
names(dup_colors) <- c("chr01", "chr04_chr13",
                         "chr06", "chr09", 
                         "chr12","chr13", "chr14",
                         "chr14_chr13")
dup_colors <- c(dup_colors, "Euploid" = "grey93")
Code
md <- gheatmap(a1, aneuploid, width=.05, colnames = FALSE, offset=5.8) +
    scale_fill_manual(name = "Duplicated\nchromosomes", 
                        values = dup_colors)+
    guides(fill = guide_legend(order = 3))+
    geom_cladelab(data = nodes_vnisublineages, 
            mapping = aes(node = mrca, label = sublineage),
            align = TRUE, face = "bold",
            fontsize = 3,
            angle = "auto", offset = 9)+
    theme(legend.position = "bottom",
    legend.direction = "vertical")
md

Code
ggsave(tree_merged_duplications_path4, md, height = 8, width = 6.5, units = "in", dpi = 1000)
Warning: Removed 2047 rows containing missing values or values outside the scale range
(`geom_text()`).

Dataset, country, source, duplications in one ring per chromosome

Code
m <- ggtree(tree, 
        ladderize = TRUE,
        layout = "circular", 
        branch.length = "none",
        size = 0.1) %<+%  metadata +
    geom_tiplab(color = "black", size = 0.3, offset = 0.01)+

    geom_hilight(data=nodes_vnisublineages, 
        aes(node=mrca, fill=sublineage), alpha = 0.8)+
        scale_fill_manual(name = "Sublineage", values = vnisublineage_shading)+
    guides(fill = FALSE)+
    new_scale_fill()+
    geom_tree(size = 0.1)+
    geom_text(aes(label = nodes_lineages$lineage[match(node, nodes_lineages$mrca)]), 
                        size = 2, , fontface = "bold",
                        hjust = 1.25, vjust = -0.5)+
    geom_tippoint(aes(color = dataset), shape = 18,
                size = 0.01)+
    scale_color_manual(name = "Dataset", values = dataset_colors)+
    guides(color = guide_legend(override.aes = list(size = 5), order = 1))

m1 <- gheatmap(m, country, width=.05, colnames=FALSE, offset=3.8) +
        scale_fill_manual(values = country_colors, name="Country",
            na.translate = FALSE, limits = countries_final)+
        guides(fill = guide_legend(order = 2, ncol = 2))+
        new_scale_fill()

m2 <- gheatmap(m1, source, width=.05, colnames=FALSE, offset=5.9) +
        scale_fill_manual(values = source_colors, name="Source", na.translate = FALSE)+
        guides(fill = guide_legend(order = 4))+
        new_scale_fill()
m3 <- gheatmap(m2, dup_chroms, width=.32, colnames = FALSE, offset=8) +
    scale_fill_manual(values = chrom_dup_colors, 
                    name="Duplicated\nchromosomes", 
                    na.translate = FALSE )+
    guides(fill = guide_legend(order = 5))+
        geom_cladelab(data = nodes_vnisublineages, 
                mapping = aes(node = mrca, label = sublineage),
                align = TRUE, face = "bold",
                fontsize = 3,
                angle = "auto", offset = 21)+
    theme(legend.position = "bottom",
    legend.direction = "vertical")
m3

Code
ggsave(tree_merged_duplications_path5, m3, height = 8, width = 6.5, units = "in", dpi = 1000)
Warning: Removed 2047 rows containing missing values or values outside the scale range
(`geom_text()`).

Dataset, country, source, duplications in one ring per chromosome no tiplab

Code
m <- ggtree(tree, 
        ladderize = TRUE,
        layout = "circular", 
        branch.length = "none",
        size = 0.1) %<+%  metadata +
    geom_hilight(data=nodes_vnisublineages, 
        aes(node=mrca, fill=sublineage), alpha = 0.8)+
        scale_fill_manual(name = "Sublineage", values = vnisublineage_shading)+
    guides(fill = FALSE)+
    new_scale_fill()+
    geom_tree(size = 0.1)+
    geom_text(aes(label = nodes_lineages$lineage[match(node, nodes_lineages$mrca)]), 
                        size = 2, , fontface = "bold",
                        hjust = 1.25, vjust = -0.5)+
    geom_tippoint(aes(color = dataset), shape = 18,
                size = 0.01)+
    scale_color_manual(name = "Dataset", values = dataset_colors)+
    guides(color = guide_legend(override.aes = list(size = 5), order = 1))

m1 <- gheatmap(m, country, width=.05, colnames=FALSE, offset=0.05) +
        scale_fill_manual(values = country_colors, name="Country",
            na.translate = FALSE, limits = countries_final)+
        guides(fill = guide_legend(order = 2, ncol = 2))+
        new_scale_fill()

m2 <- gheatmap(m1, source, width=.05, colnames=FALSE, offset=2) +
        scale_fill_manual(values = source_colors, name="Source", na.translate = FALSE)+
        guides(fill = guide_legend(order = 4))+
        new_scale_fill()
m3 <- gheatmap(m2, dup_chroms, width=.32, colnames = FALSE, offset=4) +
    scale_fill_manual(values = chrom_dup_colors, 
                    name="Duplicated\nchromosomes", 
                    na.translate = FALSE )+
    guides(fill = guide_legend(order = 5))+
        geom_cladelab(data = nodes_vnisublineages, 
                mapping = aes(node = mrca, label = sublineage),
                align = TRUE, face = "bold",
                fontsize = 3,
                angle = "auto", offset = 17)+
    theme(legend.position = "bottom",
    legend.direction = "vertical")
m3

Code
ggsave(tree_merged_duplications_path6, m3, height = 8, width = 6.5, units = "in", dpi = 1000)
Warning: Removed 2047 rows containing missing values or values outside the scale range
(`geom_text()`).

Tree with only the samples that have duplications and the references

Code
keep_strains <- c(levels(duplications_full$strain), "H99", "Bt22", "Bt89")
tree_dups <- drop.tip(tree, setdiff(tree$tip.label, keep_strains))
sublineage <- sublineage %>%
                filter(rownames(.) %in% keep_strains)%>%
                droplevels()

Tree info

Get the node number of the Most Recent Common Ancestor of each lineage

Code
VNI_node <- getMRCA(tree_dups, c("Bt139","H99"))
VNII_node <- getMRCA(tree_dups, c("8-1","C12"))
VNBI_node <- getMRCA(tree_dups, c("Bt22","NRHc5045.ENR.CLIN.ISO"))
VNBII_node <- getMRCA(tree_dups, c("Bt109","Bt89"))

nodes_lineages <- data.frame(
    lineage = c("VNI", "VNII", "VNBI", "VNBII"),
    mrca = c(VNI_node, VNII_node, VNBI_node, VNBII_node)
)
Code
VNIa4_node <- getMRCA(tree_dups, c("20427_3#26","20427_4#13"))
VNIa5_node <- getMRCA(tree_dups, c("Bt139","Bt141"))
VNIa93_node <- getMRCA(tree_dups, c("04CN-64-024","04CN-64-011"))
VNIa32_node <- getMRCA(tree_dups, c("04CN-65-072","In2632"))
VNIb_node <- getMRCA(tree_dups, c("H99","MW-RSA6134"))
VNIc_node <- getMRCA(tree_dups, c("LP-RSA3042","PMHc1031A.ENR.INI.LP"))

nodes_vnisublineages <- data.frame(
    sublineage = c(
                "VNIa-4", "VNIa-5", "VNIa-93",
                "VNIa-32", 
                "VNIb", "VNIc"),
    mrca = c(
            VNIa4_node, VNIa5_node, VNIa93_node,
            VNIa32_node,
            VNIb_node, VNIc_node))
Code
nodes_sublineages <- data.frame(
    sublineage = c("VNI", "VNII", "VNBI", "VNBII",
                "VNIa-4", "VNIa-5", "VNIa-93",
                "VNIa-32", "VNIa-X", "VNIa-Y",
                "VNIb", "VNIc"),
    mrca = c(VNI_node, VNII_node, VNBI_node, VNBII_node,
            VNIa4_node, VNIa5_node, VNIa93_node,
            VNIa32_node, VNIaX_node, VNIaY_node,
            VNIb_node, VNIc_node))
Code
sublineage_names <- c("VNIa-5","VNIa-93",
                    "VNIa-32","VNIa-4", 
                    "VNIc","VNIb")    
vnisublineage_shading <- c("gray90", "gray70", 
                        "gray90", "gray70", 
                        "gray90", "gray70") 
names(vnisublineage_shading) <- sublineage_names  

countries_final <- levels(droplevels(country[rownames(country) %in% tree_dups$tip.label, ]))

Dataset, country, duplications

Code
m <- ggtree(tree_dups, 
        ladderize = TRUE,
        layout = "rectangular", 
        branch.length = "none",
        size = 0.1) %<+%  metadata +
    geom_tiplab(color = "black", size = 1.5, offset = 0.1)+
    geom_text(aes(label = nodes_lineages$lineage[match(node, nodes_lineages$mrca)]), 
                        size = 2, , fontface = "bold",
                        hjust = 1.25, vjust = -0.5)+
    geom_hilight(data=nodes_vnisublineages, 
        aes(node=mrca, fill=sublineage), alpha = 0.8)+
        scale_fill_manual(name = "Sublineage", values = vnisublineage_shading)+
    guides(fill = FALSE)+
    new_scale_fill()+
    geom_tree(size = 0.1)+
    geom_tippoint(aes(color = dataset), shape = 18,
                size = 1.5)+
    scale_color_manual(name = "Dataset", values = dataset_colors)+
    guides(color = guide_legend(override.aes = list(size = 5), order = 1))

m1 <- gheatmap(m, country, width=.03, colnames=FALSE, offset=2.3) +
        scale_fill_manual(values = country_colors, name="Country",
            na.translate = FALSE, limits = countries_final)+
        guides(fill = guide_legend(order = 2, ncol = 2))+
        new_scale_fill()

m3 <- gheatmap(m1, dup_chroms, width=.25, colnames = FALSE, offset=2.8) +
    scale_fill_manual(values = chrom_dup_colors, 
                    name="Duplicated\nchromosomes", 
                    na.translate = FALSE )+
    guides(fill = guide_legend(order = 5, ncol = 2))+
        geom_cladelab(data = nodes_vnisublineages, 
                mapping = aes(node = mrca, label = sublineage),
                align = TRUE, face = "bold",
                fontsize = 3,
                angle = 0, offset = 5.8)+
    theme(legend.position = "bottom",
    legend.direction = "vertical")
m3

Code
ggsave(tree_merged_duplications_small1, m3, height = 5, width = 6.5, units = "in", dpi = 900)

Dataset, lineage, sublineage, duplications

Code
m <- ggtree(tree_dups, 
        ladderize = TRUE,
        layout = "rectangular", 
        branch.length = "none",
        size = 0.1) %<+%  metadata +
    geom_tiplab(color = "black", size = 1.5, offset = 0.1)+
    geom_text(aes(label = nodes_lineages$lineage[match(node, nodes_lineages$mrca)]), 
                        size = 2, , fontface = "bold",
                        hjust = 1.25, vjust = -0.5)+
    geom_hilight(data=nodes_vnisublineages, 
        aes(node=mrca, fill=sublineage), alpha = 0.8)+
        scale_fill_manual(name = "Sublineage", values = vnisublineage_shading)+
    guides(fill = FALSE)+
    new_scale_fill()+
    geom_tree(size = 0.1)+
    geom_tippoint(aes(color = dataset), shape = 18,
                size = 1.5)+
    scale_color_manual(name = "Dataset", values = dataset_colors)+
    guides(color = guide_legend(override.aes = list(size = 5), order = 1))

m2 <- gheatmap(m, dup_chroms, width=.25, colnames = FALSE, offset=2) +
    scale_fill_manual(values = chrom_dup_colors, 
                    name="Duplicated\nchromosomes", 
                    na.translate = FALSE )+
    guides(fill = guide_legend(order = 5, ncol = 2))+
        geom_cladelab(data = nodes_vnisublineages, 
                mapping = aes(node = mrca, label = sublineage),
                align = TRUE, face = "bold",
                fontsize = 3,
                angle = 0, offset = 5)+
    theme(legend.position = "bottom",
    legend.direction = "vertical")
m2

Code
ggsave(tree_merged_duplications_small2, m2, height = 5, width = 6.5, units = "in", dpi = 900)

Lineage, duplications, sublineage

Code
m <- ggtree(tree_dups, 
        ladderize = TRUE,
        layout = "rectangular", 
        branch.length = "none",
        size = 0.1) %<+%  metadata +
    geom_tiplab(color = "black", size = 1.5, offset = 0.1)+
    geom_text(aes(label = nodes_lineages$lineage[match(node, nodes_lineages$mrca)]), 
                        size = 2, , fontface = "bold",
                        hjust = 1.25, vjust = -0.5)+
    geom_hilight(data=nodes_vnisublineages, 
        aes(node=mrca, fill=sublineage), alpha = 0.8)+
        scale_fill_manual(name = "Sublineage", values = vnisublineage_shading)+
    guides(fill = FALSE)+
    new_scale_fill()+
    geom_tree(size = 0.1)

m2 <- gheatmap(m, dup_chroms, width=.25, colnames = FALSE, offset=2) +
    scale_fill_manual(values = chrom_dup_colors, 
                    name="Duplicated\nchromosomes", 
                    na.translate = FALSE )+
    guides(fill = guide_legend(order = 5, ncol = 2))+
        geom_cladelab(data = nodes_vnisublineages, 
                mapping = aes(node = mrca, label = sublineage),
                align = TRUE, face = "bold",
                fontsize = 3,
                angle = 0, offset = 5)+
    theme(legend.position = "bottom",
    legend.direction = "vertical")
m2

Code
ggsave(tree_merged_duplications_small3, m2, height = 5, width = 6.5, units = "in", dpi = 900)

Lineage, duplications

Code
m <- ggtree(tree_dups, 
        ladderize = TRUE,
        layout = "rectangular", 
        branch.length = "none",
        size = 0.1) %<+%  metadata +
    geom_tiplab(color = "black", size = 1.5, offset = 0.1)+
    geom_text(aes(label = nodes_lineages$lineage[match(node, nodes_lineages$mrca)]), 
                        size = 2, , fontface = "bold",
                        hjust = 1.25, vjust = -0.5)

m2 <- gheatmap(m, dup_chroms, width=.25, colnames = FALSE, offset=2) +
    scale_fill_manual(values = chrom_dup_colors, 
                    name="Duplicated\nchromosomes", 
                    na.translate = FALSE )+
    guides(fill = guide_legend(order = 5, ncol = 2))+
    theme(legend.position = "bottom",
    legend.direction = "vertical")
m2

Code
ggsave(tree_merged_duplications_small4, m2, height = 5, width = 6.5, units = "in", dpi = 900)

Lineage, duplications

Code
m <- ggtree(tree_dups, 
        ladderize = TRUE,
        layout = "rectangular", 
        branch.length = "none",
        size = 0.1) %<+%  metadata +
    geom_tiplab(color = "black", size = 1.5, offset = 0.1)+
    geom_text(aes(label = nodes_lineages$lineage[match(node, nodes_lineages$mrca)]), 
                        size = 2, , fontface = "bold",
                        hjust = 1.25, vjust = -0.5)

m2 <- gheatmap(m, dup_chroms, width=.25, colnames = FALSE, offset=2) +
    scale_fill_manual(values = chrom_dup_colors, 
                    name="Duplicated\nchromosomes", 
                    na.translate = FALSE )+
    guides(fill = guide_legend(order = 5, ncol = 2))+
    theme(legend.position = "bottom",
    legend.direction = "vertical")
m2

Code
ggsave(tree_merged_duplications_small5, m2, height = 5, width = 6.5, units = "in", dpi = 900)

Lineage-sublineage, duplications

Code
m <- ggtree(tree_dups, 
        ladderize = TRUE,
        layout = "rectangular", 
        branch.length = "none",
        size = 0.1) %<+%  metadata +
    geom_text(aes(label = nodes_sublineages$sublineage[match(node, nodes_sublineages$mrca)]), 
                        size = 2, , fontface = "bold",
                        hjust = 1.25, vjust = -0.5)

m3 <- gheatmap(m, dup_chroms, width=.25, colnames = FALSE, offset=0.1) +
    scale_fill_manual(values = chrom_dup_colors, 
                    name="Duplicated\nchromosomes", 
                    na.translate = FALSE )+
    guides(fill = guide_legend(order = 5))+
    theme(legend.position = "right",
    legend.direction = "vertical")
m3

Code
ggsave(tree_merged_duplications_small6, m3, height = 5, width = 6.5, units = "in", dpi = 900)

Lineage-sublineage, duplications

Code
m <- ggtree(tree_dups, 
        ladderize = TRUE,
        layout = "rectangular", 
        branch.length = "none",
        size = 0.1) %<+%  metadata +
    geom_text(aes(label = nodes_sublineages$sublineage[match(node, nodes_sublineages$mrca)]), 
                        size = 2, , fontface = "bold",
                        hjust = 1.25, vjust = -0.5)+
    geom_hilight(data=nodes_vnisublineages, 
        aes(node=mrca, fill=sublineage), alpha = 0.8)+
        scale_fill_manual(name = "Sublineage", values = vnisublineage_shading)+
    guides(fill = FALSE)+
    new_scale_fill()+
    geom_tree()

m3 <- gheatmap(m, dup_chroms, width=.25, 
                colnames = TRUE, colnames_position = "top",
                colnames_angle = 45,
                colnames_offset_y = 0.5,
                font.size = 2,
                offset=0.1) +
    scale_fill_manual(values = chrom_dup_colors, 
                    name="Duplicated\nchromosomes", 
                    na.translate = FALSE )+
    guides(fill = guide_legend(order = 5))+
    theme(legend.position = "none",
    legend.direction = "vertical")
m3

Code
ggsave(tree_merged_duplications_small7, m3, height = 5, width = 6.5, units = "in", dpi = 900)

Lineage-sublineage, duplications (alternating colors)

Code
chrom_colors <- c("deepskyblue4", "darkslategray3",
                    "deepskyblue4", "darkslategray3",
                    "deepskyblue4", "darkslategray3",
                    "deepskyblue4")
names(chrom_colors) <- c("chr01", "chr04",
                         "chr06", "chr09", 
                         "chr12","chr13", "chr14")

chrom_dup_colors <- c(chrom_colors, "Euploid" = "grey93")
Code
m <- ggtree(tree_dups, 
        ladderize = TRUE,
        layout = "rectangular", 
        branch.length = "none",
        size = 0.1) %<+%  metadata +
    geom_text(aes(label = nodes_sublineages$sublineage[match(node, nodes_sublineages$mrca)]), 
                        size = 2, , fontface = "bold",
                        hjust = 1.25, vjust = -0.5)+
    geom_hilight(data=nodes_vnisublineages, 
        aes(node=mrca, fill=sublineage), alpha = 0.8)+
        scale_fill_manual(name = "Sublineage", values = vnisublineage_shading)+
    guides(fill = FALSE)+
    new_scale_fill()+
    geom_tree()

m3 <- gheatmap(m, dup_chroms, width=.25, 
                colnames = TRUE, colnames_position = "top",
                colnames_angle = 45,
                colnames_offset_y = 0.5,
                font.size = 2,
                offset=0.1) +
    scale_fill_manual(values = chrom_dup_colors, 
                    name="Duplicated\nchromosomes", 
                    na.translate = FALSE )+
    guides(fill = guide_legend(order = 5))+
    theme(legend.position = "none",
    legend.direction = "vertical")
m3

Code
ggsave(tree_merged_duplications_small8, m3, height = 5, width = 6.5, units = "in", dpi = 900)

Lineage-sublineage, duplications (one colors)

Code
chrom_colors <- rep("deepskyblue4",7)
names(chrom_colors) <- c("chr01", "chr04",
                         "chr06", "chr09", 
                         "chr12","chr13", "chr14")

chrom_dup_colors <- c(chrom_colors, "Euploid" = "grey93")
Code
m <- ggtree(tree_dups, 
        ladderize = TRUE,
        layout = "rectangular", 
        branch.length = "none",
        size = 0.1) %<+%  metadata +
    geom_text(aes(label = nodes_sublineages$sublineage[match(node, nodes_sublineages$mrca)]), 
                        size = 2, , fontface = "bold",
                        hjust = 1.25, vjust = -0.5)+
    geom_hilight(data=nodes_vnisublineages, 
        aes(node=mrca, fill=sublineage), alpha = 0.8)+
        scale_fill_manual(name = "Sublineage", values = vnisublineage_shading)+
    guides(fill = FALSE)+
    new_scale_fill()+
    geom_tree()

m3 <- gheatmap(m, dup_chroms, width=.25, 
                colnames = TRUE, colnames_position = "top",
                colnames_angle = 45,
                colnames_offset_y = 0.5,
                font.size = 2,
                 offset=0.1) +
    scale_fill_manual(values = chrom_dup_colors, 
                    name="Duplicated\nchromosomes", 
                    na.translate = FALSE )+
    guides(fill = guide_legend(order = 5))+
    theme(legend.position = "none",
    legend.direction = "vertical")
m3

Code
ggsave(tree_merged_duplications_small9, m3, height = 5, width = 6.5, units = "in", dpi = 900)

Lineage-sublineage, duplications in one bar

Code
m3<- gheatmap(m, aneuploid, width=.05, colnames = FALSE, offset=0.5) +
        scale_fill_brewer(palette = "Dark2",
                    name="Duplicated\nchromosomes", 
                    na.translate = FALSE )
m3

Code
ggsave(tree_merged_duplications_small10, m3, height = 5, width = 6.5, units = "in", dpi = 900)